<!--
  Expects the following variables:
  podTemplate
  imagesByDockerReference (optional)
  builds (optional)
  detailed (optional)
  addHealthCheckUrl (optional)
 -->

 <!-- Prompt to add health checks if missing. -->
<div ng-if="detailed && addHealthCheckUrl && !(podTemplate | hasHealthChecks)" class="alert alert-info">
  <span class="pficon pficon-info" aria-hidden="true"></span>
  <span ng-if="podTemplate.spec.containers.length === 1">This container has no health checks</span>
  <span ng-if="podTemplate.spec.containers.length > 1">Not all containers have health checks</span>
  to ensure your application is running correctly.
  <a ng-href="{{addHealthCheckUrl}}" class="nowrap">Add health checks</a>
</div>

<div class="pod-template-container">
  <div class="pod-template-block" ng-repeat="container in podTemplate.spec.containers">
    <div class="pod-template">
      <div class="component-label">Container: {{container.name}}</div>
      <div row ng-if="container.image" class="pod-template-image icon-row">
        <div>
          <span class="pficon pficon-image" aria-hidden="true"></span>
        </div>
        <div flex class="word-break">
          <span class="pod-template-key">Image:</span>
          <span ng-if="!imagesByDockerReference[container.image]">{{container.image | imageStreamName}}</span>
          <span ng-if="imagesByDockerReference[container.image]">
            <a ng-href="{{imagesByDockerReference[container.image].imageStreamName | navigateResourceURL : 'ImageStream' : imagesByDockerReference[container.image].imageStreamNamespace}}">{{container.image | imageStreamName}}</a>
            <span class="hash" title="{{imagesByDockerReference[container.image].metadata.name}}">{{imagesByDockerReference[container.image].metadata.name | stripSHAPrefix | limitTo: 7}}</span>
            <span ng-if="imagesByDockerReference[container.image].dockerImageMetadata.Size" class="small text-muted nowrap">
              {{imagesByDockerReference[container.image].dockerImageMetadata.Size | humanizeSize}}
            </span>            
          </span>
        </div>
      </div>
      <div ng-if="imagesByDockerReference && container.image && (image = imagesByDockerReference[container.image])" class="pod-template-build">
        <div row class="icon-row" ng-if="build = (image | buildForImage : builds)">
          <div>
            <span class="fa fa-refresh" aria-hidden="true"></span>
          </div>
          <div flex class="word-break">
            <span class="pod-template-key">Build:</span>
            <span ng-if="build | configURLForResource">
              <a ng-href="{{build | configURLForResource}}">{{build | buildConfigForBuild}}</a>,
            </span>
            <a ng-href="{{build | navigateResourceURL}}">
              <span ng-if="(build | annotation : 'buildNumber')">#{{build | annotation : 'buildNumber'}}</span>
              <span ng-if="!(build | annotation : 'buildNumber')">{{build.metadata.name}}</span>
            </a>
          </div>
        </div>
        <div row class="icon-row" ng-if="build.spec.source">
          <div>
            <span class="fa fa-code" aria-hidden="true"></span>
          </div>
          <div flex>
            <span class="pod-template-key">Source:</span>
            <span ng-switch="build.spec.source.type">
              <span ng-switch-when="Git">
                <span ng-if="build.spec.revision.git.commit">
                  {{build.spec.revision.git.message}}
                  <osc-git-link
                    class="hash"
                    uri="build.spec.source.git.uri"
                    ref="build.spec.revision.git.commit">{{build.spec.revision.git.commit | limitTo:7}}</osc-git-link>
                  <span ng-if="detailed && build.spec.revision.git.author">
                    authored by {{build.spec.revision.git.author.name}}
                  </span>
                </span>
                <span ng-if="!build.spec.revision.git.commit">
                  <osc-git-link uri="build.spec.source.git.uri">{{build.spec.source.git.uri}}</osc-git-link>
                </span>
              </span>
              <span ng-switch-default>
                {{build.spec.source.type || 'Unknown'}}
              </span>
            </span>
          </div>
        </div>
      </div>

      <div row ng-if="container.ports.length > 0" class="pod-template-ports icon-row">
        <div>
          <span data-icon="" aria-hidden="true" style="font-size:16px;line-height:normal"></span>
        </div>
        <div flex class="word-break">
          <span class="pod-template-key">Ports:</span>
          <span ng-repeat="port in container.ports | orderBy: 'containerPort'">
            <span class="nowrap">{{port.containerPort}}/{{port.protocol}}<span ng-if="port.name">&thinsp;({{port.name}})</span><span ng-if="port.hostPort">&thinsp;<span class="port-icon">&#8594;</span>&thinsp;{{port.hostPort}}</span></span><span ng-if="!$last">, </span>
          </span>
        </div>
      </div>

      <div row ng-if="detailed" ng-repeat="mount in container.volumeMounts" class="icon-row">
        <div>
          <span aria-hidden="true" class="fa fa-database"></span>
        </div>
        <div flex class="word-break">
          <span class="pod-template-key">Mount:</span>
          <span>
            {{mount.name}}&#8201;&#8594;&#8201;<span>{{mount.mountPath}}</span>
          </span>
        </div>
      </div>

      <div row ng-if="detailed && (container.resources.requests.cpu || container.resources.limits.cpu)" class="icon-row">
        <div>
          <i class="fa fa-area-chart" aria-hidden="true"></i>
        </div>
        <div flex>
          <span class="pod-template-key">CPU:</span>
          <span ng-if="container.resources.requests.cpu && container.resources.limits.cpu">
            {{container.resources.requests.cpu | usageWithUnits: 'cpu'}} to {{container.resources.limits.cpu | usageWithUnits: 'cpu'}}
          </span>
          <span ng-if="!container.resources.requests.cpu">
            {{container.resources.limits.cpu | usageWithUnits: 'cpu'}} limit
          </span>
          <span ng-if="!container.resources.limits.cpu">
            {{container.resources.requests.cpu | usageWithUnits: 'cpu'}} requested
          </span>
        </div>
      </div>

      <div row ng-if="detailed && (container.resources.requests.memory || container.resources.limits.memory)" class="icon-row">
        <div>
          <i class="fa fa-area-chart" aria-hidden="true"></i>
        </div>
        <div flex>
          <span class="pod-template-key">Memory:</span>
          <span ng-if="container.resources.requests.memory && container.resources.limits.memory">
            {{container.resources.requests.memory | usageWithUnits: 'memory'}} to {{container.resources.limits.memory | usageWithUnits: 'memory'}}
          </span>
          <span ng-if="!container.resources.requests.memory">
            {{container.resources.limits.memory | usageWithUnits: 'memory'}} limit
          </span>
          <span ng-if="!container.resources.limits.memory">
            {{container.resources.requests.memory | usageWithUnits: 'memory'}} requested
          </span>
        </div>
      </div>

      <div row ng-if="detailed && container.readinessProbe" class="icon-row">
        <div>
          <i class="fa fa-medkit" aria-hidden="true"></i>
        </div>
        <div flex>
          <span class="pod-template-key">Readiness Probe:</span>
          <probe probe="container.readinessProbe"></probe>
        </div>
      </div>

      <div row ng-if="detailed && container.livenessProbe" class="icon-row">
        <div>
          <i class="fa fa-medkit" aria-hidden="true"></i>
        </div>
        <div flex>
          <span class="pod-template-key">Liveness Probe:</span>
          <probe probe="container.livenessProbe"></probe>
        </div>
      </div>

      <div
        extension-point
        extension-name="container-links"
        extension-types="link dom"
        extension-args="[container, podTemplate]"></div>

    </div>
  </div>
</div>
